<?php
final class PagerRewrite
{
    private $RewriteName=NULL;
    private $ParamsName=NULL;
    private $ExtName=NULL;

    public  function __construct($rewriteName,$paramsName,$extName)
    {
        $this->RewriteName=$rewriteName;
        $this->ParamsName=$paramsName;
        $this->ExtName=$extName;
    }

    public function Get($url)
    {
        $url_params='';
        {
            //把重写的URL地址里的参数转换为数组
            $params=array();
            $paramsArray=explode('&',$url);
            for($i=1;$i<count($paramsArray);$i++)
            {
                $parameter=explode('=',$paramsArray[$i]);
                $parameterName=$parameter[0];
                $parameterValue=$parameter[1];
                $params[$parameterName]=$parameterValue;
            }
            //遍历传进来的ParamsName数组，并在上面的数组中找到值
            foreach(explode(',',$this->ParamsName) as $parameterName)
            {
                if(@$params[$parameterName]){
                    $url_params.='/'.$params[$parameterName];
                }
            }
            $url_params.='/'.$params['page'];
        }        
        $newURL=$this->RewriteName.$url_params.'.'.$this->ExtName;
        $newURL=str_replace('//','/',$newURL);
        return $newURL;
    }
}
?>